<?php  
/* 
Template Name: Page San Pham
*/
?>
<?php get_header(); ?>
<div class="cy-content">
	<?php get_sidebar();?>
    <div class="cy-content-center">
    <?php locate_template('block/block-search.php', true); ?>
    <div class="cy-content-title">
    <h2>camera quan sát</h2>
    </div><!--cy-content-title-->
    <ul class="cy-products">
    <?php 	  
    // Get terms for post
   		$terms = get_terms("danh_muc_san_pham");
        //print_r($terms);
		$count = count($terms);
		if ( $count > 0 ){
		foreach ( $terms as $term ) {	
                 ?>
                 <li class="cy-product-item" >
                        <div class="cy-product-title">
                             <span class="cy-product-item-f"><?php 
                        		echo  $term->name;
                        	 ?></span><!--cy-product-item-f-->        	
                             <ul class="tab_product">
                                 <?php
                                 $tem=1;
                                 $loop = new WP_Query(array('post_type'=>'san_pham','danh_muc_san_pham'=>$term->slug,'order'=>'DESC'));?>
                                 <?php while ( $loop->have_posts() ) : $loop->the_post(); //bat dau vong lap ?>
                                 
                                 <li <?php if($tem==1){
                                    echo "class='active'";
                                    }?> >
                                    <a  href="#<?php  echo $term->slug;echo '-'; echo $post->ID;?>" >
                                    <?php the_title();?>
                                    </a>
                                    </li>
                                 <?php 
                                 $tem ++;
                                // echo $tem;
                                 endwhile; //ket thuc vong lap ?>
                                 <?php wp_reset_query();?>
                        	 </ul><!--tab_product-->
                        </div><!--cy-product-title-->
                        <?php
                        $loop1 = new WP_Query(array('post_type'=>'san_pham','danh_muc_san_pham'=>$term->slug,'order'=>'DESC'));
                        while ( $loop1->have_posts() ) : $loop1->the_post(); //bat dau vong lap 
                        ?>
                       <div id="<?php echo $term->slug;echo "-";echo $post->ID;?>"  class="cy-product-content">
                                <a href="<?php echo get('hinh');?>" id="example1"><img src="<?php echo get('hinh');?>" alt="example1"></a>
                <div class="cy-title-product"><a href="<?php the_permalink();?>"><?php the_title() ?></a></div>
                <ul class="cy-product-content-i" >
                                    <li>Mã sản phẩm : <?php echo get('ma_san_pham');?></li>
                                    <li>Đơn vị tính : <?php echo get('don_vi_tinh');?></li>
                                    <li>Xuất xứ : <?php echo get('xuat_xu');?></li>
                                    <li>Trạng thái: <span class="cy-status"><?php if(get('trang_thai')==0){echo "Còn hàng";}else{echo "Hết hàng";};?></span></li>
                                </ul><!--cy-product-content-i-->
                                  <div class="cy-product-extensions">
                                         <a href="<?php the_permalink();?>"><div class="cy-read-more">
                                         </div><!--cy-read-more--></a>
                            			<?php if(trim(get('gia_khuyen_mai')) !=""){?>
                                         <div class="cy-price-gach">
                                         Giá : <?php echo number_format(get('gia'),0);?>VNĐ
                                         </div><!--cy-price-gach-->
                                         <div class="cy-price-km">
                                         Giá khuyến mãi : <span><?php echo number_format(get('gia_khuyen_mai'),0);?>VNĐ</span>
                                          </div><!--cy-price-km-->
                                  
                                   
                                   <?php }else{ ?>
                                   <div class="cy-price">
                                      Giá : <?php number_format(get('gia'),0);?> VNĐ
                                    </div><!--cy-price-->
                                   <?php } ?>
                                   </div><!--cy-product-extensions-->
                       </div><!--.cy-product-content-->
                       <?php  endwhile; 
                       //ket thuc vong lap ?>
                       <?php wp_reset_query();?>
               </li><!--cy-product-item-->
       <?php  } ?>
       <?php } ?>
    </ul>
    </div><!--cy-content-center-->  
</div><!--cy-content-->
<?php get_footer(); ?>